import corejuliano.designpattern.observer.*;
import corejuliano.designpattern.mvc.*;
import util.*;
import corejuliano.*;
import flash.geom.*;


class corejuliano.designpattern.mvc.View implements Observer
{
	private var model:Model;
	private var graphic:MovieClip;
	
	public function View(canvas:MovieClip, model:Model)
	{	
		this.model = model;
		createMovieClip(canvas);
	}
	
	public function createMovieClip(canvas:MovieClip):Void
	{
		graphic = canvas.attachMovie(model.getId(),model.getId() + canvas.getNextHighestDepth(),canvas.getNextHighestDepth());
	}
	
	public function update(event:String, observable:Observable):Void	
	{
		// testo se o model do cara que esta sendo observado e
		//igual ao model atual, o model corrente
		if (Controller(observable).getModel() == model)
			if(event == GameManager.UPDATE_SCREEN)
				updateScreen();			
		
	}
	
	public function updateScreen():Void
	{	
		graphic._x = model.getPosition().x;
		graphic._y = model.getPosition().y;
	}
	
	public function destroy():Void
	{
		graphic.removeMovieClip();
		model.destroy();
	}

	public function toString(Void):String
	{
		return "corejuliano.designpattern.mvc.View";
	}

}